package logic.newLogic2;

import guiDisplay.MovieComment;
import guiDisplay.MovieData;
import guiDisplay.MovieList;

import java.util.GregorianCalendar;
import java.util.TreeSet;

import data.MovieTuple;
import data.RatingTuple;
import data.SystemData;

public class SystemHandler3 {

	public SystemHandler3(){
	}

//	public RatingTuple getRandomRec(){
//		return SystemData.getInstance().getRandomRec();
//	}

	public void addRating(String user , String movie, String rating , String description){
		System.out.println("user name is "+user);
		TreeSet<RatingTuple> ratings=SystemData.getInstance().getRatingsByUser(user);
		boolean rated=false;

		for (RatingTuple r : ratings){
			if (r.get_movie().get_name().equals(movie)){
				rated=true;
				break;
			}
		}
		if(rated)
			changeRating(user, movie, rating, description);
		else SystemData.getInstance().addRating(user , movie, rating , description);
	}

	public void changeRating(String user , String movie, String rate , String description){
		SystemData.getInstance().editRating(user,movie,description,rate,GregorianCalendar.getInstance().getTime().toString());
	}

	public MovieData getMovieData(String name) {
		MovieTuple movie = SystemData.getInstance().getMovie(name);
		TreeSet<RatingTuple> ratings = movie.getRatings();
		MovieComment[] comments = new MovieComment[ratings.size()];
		int i = 0;
		for (RatingTuple r : ratings){
			comments[i] = new MovieComment(r.get_user().get_name(),r.get_rating()+"",r.get_date(),r.get_description());
			i++;
		}
		MovieData d = new MovieData(movie.get_name(),movie.get_year()+"",""+movie.get_length(),movie.get_language(),movie.get_director(),movie.get_category(),movie.get_rating()+"",movie.get_raters()+"",movie.get_picture()+"",comments );
		return d;
	}

	public String[] getMovies() {
		return SystemData.getInstance().getMovieNames();
	}

	public MovieList getMovies(int start) {
		return SystemData.getInstance().getMovieNames(start);
	}

	public String[] getUsers(String user) {
		return SystemData.getInstance().getUserNames(user);
	}

	public String[] getRegUsers() {
		return SystemData.getInstance().getRegUserNames();
	}

	public String[] getAllNmaes() {
		return SystemData.getInstance().getAllNames();
	}

	public String[] getNotMngUsers() {
		return SystemData.getInstance().getNotMngUsersNames();
	}

}
